/**
 * 功能描述
 */
define(function (require, exports, module) {
	var Subnav = require("subnav");
	var aw = require("ajaxwrapper");
	var user = require("store").get("user");
	
    var instance = {
        initComponent: function (params, widget) {
        	var subnav = new Subnav({
        		parentNode:".J-subnav",
        		model:{
        			title:"散客退房结算单",
        			items : [{
        				id: "servicePoint",
        				type: "buttongroup",
        				all :{
        					show:false,
        					first:false
        				},
        				tip :"服务点",
        				keyField: "pkServicePoint",
        				valueField: "name",
//        				url: "api/servicepoint/operableservicepoints",
        				items:user.privateServicePoints,
        				params:function(){
        					return{
        						fetchProperties: "pkServicePoint,name"
        					}
        				},
//        				lazy: true,
        				handler : function(key,element){
        					widget.get("grid").refresh();
        				}
        			},{
        				id: "status",
        				tip:"状态",
        				type:"buttongroup",
        				items:[{
        					key: "NoConfirm",
        					value: "待确认"
        				},{
        					key: "Confirm",
        					value: "已确认"
        				}],
        				handler: function(){
        					widget.get("grid").refresh();
        				}
        			},{
        				id :"checkOutDate",
        				type : "daterange",
        				tip:"退住时间",
        				ranges:{
        					"本年": [moment().startOf("year"), moment().endOf("days")]
        				},
        				handler : function(time){
        					widget.get("grid").refresh();
        				}
        			},
        			{
        				id:"return",
        				type:"button",
        				text:"返回",
        				show:false,
        				handler:function(){
        					var forms = widget.get("forms");
        					for(var i = 0; i < forms.length; i++){
        						forms[i].destroy();
        					}
        					widget.toGrid();
        				}
        			},{
        				id: "print",
        				type: "button",
						text: "个人明细打印",
						show: false,
						handler: function(){
							widget.handler.subnavHandler.print(widget);
						}
        			},{
        				id: "totalprint",
        				type: "button",
						text: "结算单打印",
						show:false,
						handler: function(){
							
							var idata = {};
							var endGrid = widget.get("endGrid").getData();
							var personal = [];
							for(var i=0;i<endGrid.length;i++){
								var personalObj = {};
								var nonMemberName = endGrid[i].roomPersonalInfo.nonMemberRegister;
								var roomPersonal = endGrid[i].roomPersonalInfo.personalInfo;
								if(nonMemberName){
									personalObj.name = nonMemberName.signUpRegister.personalInfo.name;
								}else if(roomPersonal){
									personalObj.name = roomPersonal.name;
								}else{
									personalObj.name = "";
								}
								
								personalObj.code = endGrid[i].roomPersonalInfo.roomRegister.room.code;
								personal.push(personalObj);
							}
							
							idata["tatalGrid"] = widget.get("totalGrid").getData();
							idata["endGrid"] = personal;
							
							var allform = widget.get("form");
							var allFormData = allform.getData();
							idata.destination = allFormData["desName"];
							idata.signUpNumber = allFormData["signUpNumber"];
							idata.checkInDate = allFormData["checkInDate"];
							idata.checkOutDate = allFormData["checkOutDate"];
							idata.operatorName = allFormData["operatorName"];
							idata.statementDate = allFormData["settlementDate"];
							
							window.open("assets/eling/elcms/travel/nonmemcheckoutconfirm/src/plancheckoutprint.html?obj="+JSON.stringify(idata));
						}
        			},{

        				id: "paymentMethod",
        				type: "buttongroup",
        				tip:"结算方式",
						  items: [{
					          key: "all",
					          value: "全部"
					        }, {
					          key: "Cash",
					          value: "现金"
					        }, {
						      key: "WipeCard",
						      value: "刷卡"
						    }, {
							  key: "Transfer",
							  value: "转账"
							}, {
							  key: "OnCredit",
							  value: "挂账"
							}],
						handler: function(key){
							widget.get("grid").refresh();
						}
        			}]
        		}
        	});
        	widget.set("subnav", subnav);
        }
    };
    module.exports = instance;
});
